/****************************************************************************
 * Copyright 2009 Huascar A. Sanchez                                        *
 *                                                                          *
 * Licensed under the Apache License, Version 2.0 (the "License");          *
 * you may not use this file except in compliance with the License.         *
 * You may obtain a copy of the License at                                  *
 *                                                                          *
 *     http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                          *
 * Unless required by applicable law or agreed to in writing, software      *
 * distributed under the License is distributed on an "AS IS" BASIS,        *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 * See the License for the specific language governing permissions and      *
 * limitations under the License.                                           *
 ****************************************************************************/
package com.gotobject.filter.builders;

import com.gotobject.filter.Filter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * a class metadata of a class literal. this is a useful
 * class when it comes to dealing with the Java Reflection API.
 *
 * @author huascar.sanchez@gmail.com (Huascar A. Sanchez)
 */
public class ClassMetadataFilteringBuilder {
    private final Class<?> klass;
    private final Filter filter;

    public ClassMetadataFilteringBuilder(Class<?> klass, Filter filter){
        this.klass  = klass;
        this.filter = filter;
    }

    public FilteringBuilder<Annotation> annotations(){
        return filter.from(Arrays.asList(klass.getDeclaredAnnotations()));
    }

    public FilteringBuilder<Class<?>> classes(){
        return filter.from(Arrays.asList(klass.getDeclaredClasses()));
    }

    public FilteringBuilder<Constructor<?>> constructors(){
        return filter.from(Arrays.asList(klass.getDeclaredConstructors()));
    }

    public FilteringBuilder<Field> fields(){
        return filter.from(Arrays.asList(klass.getDeclaredFields()));
    }

    public FilteringBuilder<Method> methods(){
        return filter.from(Arrays.asList(klass.getDeclaredMethods()));
    }
}
